package com.millstein.tsinglog.mapper.biz;

import com.millstein.tsinglog.mapper.BaseMapper;
import com.millstein.tsinglog.model.pojo.Notice;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface NoticeMapper extends BaseMapper<Notice> {
    /**
     * server用，根据id查询公告
     * @param id
     * @return
     */
    @Select("SELECT `id`, `content`, `link`, `type`, `usable`, `status`, `create_time` createTime, " +
            "`update_time` updateTime FROM `biz_notice` " +
            "where `status` = 1 and `id` = #{id};")
    Notice selectNoticeByPrimaryKeyForServer(@Param("id") Long id);

    /**
     * web用，根据id查询公告
     * @param id
     * @return
     */
    @Select("SELECT `id`, `content`, `link`, `type`, `usable`, `status`, `create_time` createTime, " +
            "`update_time` updateTime FROM `biz_notice` " +
            "where `usable` = 1 and `status` = 1 and `id` = #{id};")
    Notice selectNoticeByPrimaryKeyForWeb(@Param("id") Long id);
    /**
     * 获取前台公告
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Select("select id, content, link from `biz_notice` where type = 1 and usable = 1 and status = 1 order by " +
            "update_time desc limit #{currentPage}, #{pageSize}")
    List<Map<String, Object>> getNoticeListForPortal(@Param("currentPage") Integer currentPage,
                                                     @Param("pageSize") Integer pageSize);
}
